<!-- 账单修改记录 -->
<template>
  <!-- 重置密码dialog -->
  <el-dialog title="预警配置" :visible.sync="visible" width="40%">
    <div class="app-container">
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="mini"
        :inline="true"
        v-show="showSearch"
        label-width="86px"
      >
        <el-form-item label="承运商ID" prop="carrierId" label-width="68px">
          <el-input
            placeholder="请输入承运商ID"
            v-model="queryParams.carrierId"
          >
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="账单ID" prop="billId" label-width="58px">
          <el-input
            placeholder="请输入供应商ID"
            v-model="queryParams.billId"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="repairList">
        <!-- <el-table-column type="selection" width="55" align="center" /> -->
        <el-table-column label="回款单ID" align="center" prop="id" />
        <el-table-column
          label="合同主体公司"
          align="center"
          prop="createTime"
          width="160"
        >
        </el-table-column>
        <el-table-column label="客户名称" align="center" prop="carNumber" />
        <el-table-column
          label="回款信息"
          align="center"
          prop="carLicensePlate"
        />
        <el-table-column label="备注" align="center" prop="repairType" />
        <el-table-column
          label="回款状态"
          align="center"
          prop="repairTime"
          width="160px"
        >
        </el-table-column>
        <el-table-column
          label="创建时间"
          align="center"
          prop="updateTime"
          width="160px"
        >
          <template slot-scope="scope">
            <span>{{ formatDate(scope.row.updateTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="确认时间"
          align="center"
          prop="updateTime"
          width="160px"
        >
          <template slot-scope="scope">
            <span>{{ formatDate(scope.row.updateTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="创建人"
          align="center"
          prop="repairTime"
          width="160px"
        ></el-table-column>
        <el-table-column
          label="确认人"
          align="center"
          prop="repairTime"
          width="160px"
        ></el-table-column>
        <el-table-column
          label="操作"
          align="center"
          fixed="right"
          width="120px"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleDetail(scope.row)"
              v-hasPermi="['service:repair:edit']"
              >详情</el-button
            >
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleAlready(scope.row)"
              v-hasPermi="['service:repair:edit']"
              >已到账</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </el-dialog>
</template>
  
  <script>
import {
  listRepair,
  getRepair,
  delRepair,
  addRepair,
  updateRepair,
} from "@/api/service/repair";

import { listCars } from "@/api/service/cars";
import { formatDate } from "@/utils";

export default {
  name: "Repair",
  components: {},
  data() {
    return {
      visible: false,
      dataList: [],
      carList: [], // che
      repairTypeList: [
        "待抵出",
        "抵出中",
        "已抵出",
        "液压系统",
        "定期保养",
        "换季保养",
      ],
      businessTypes: ["合同约定", "非合同约定"],
      // 遮罩层
      loading: true,
      // 选中数组
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车辆维修记录表格数据
      repairList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        supplierName: null,
        carrierName: null,
        supplierId: null,
        carrierId: null,
        billId: null,
        applyTime: "",
        businessType: "",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        carId: [{ required: true, message: "车辆id不能为空", trigger: "blur" }],
      },
    };
  },
  created() {
    this.getList();
  },
  watch: {
    open(n, o) {
      if (n) {
        this.$nextTick(() => {
          this.getCarList();
        });
      }
    },
  },
  methods: {
    // 初始化函数--->父级调用
    handelInit(val) {
      console.log(val);
      if (val.id) {
      } else {
        this.$message.error("获取仓库详情失败");
      }
      this.initObj = val;
      this.visible = true;
    },
    handleAdd() {
      this.$router.push({
        name: "OuterAction",
      });
    },
    handleCarChange(val) {},

    getCarList() {
      listCars({ pageNum: 1, pageSize: 10000 }).then((res) => {
        this.carList = res.rows;
      });
    },
    formatDate,
    // 详情
    handleDetail(val) {
      this.$refs.detailView.handelInit(val);
    },
    // 已到账
    handleAlready(val) {
      this.$refs.alreadyMoney.handelInit(val);
    },
    getList() {
      this.loading = true;
      listRepair({
        ...this.queryParams,
        startTime: this.queryParams.times?.[0],
        endTime: this.queryParams.times?.[1],
      }).then((response) => {
        this.repairList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        carId: null,
        carNumber: null,
        carLicensePlate: null,
        repairTime: null,
        repairType: null,
        repairShop: null,
        repairCost: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        repairCostDetail: null,
        invoices: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.times = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("确定要删除吗？")
        .then(function () {
          return delRepair(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>
  